﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LotteryVote.Entity;
using LotteryVote.Utility;

namespace LotteryVote.Logic.Web
{
    public class ClientControler
    {
        public static void WriteCompanyNumLenToClient(IList<LotteryCompany> companyList)
        {
            NumLenFacade numLenFacade = new NumLenFacade();
            List<CompanyNumLen> numLens = new List<CompanyNumLen>();
            foreach (var company in companyList)
            {
                var numLenSupport = numLenFacade.GetNumLengthByCompanyId(company.CompanyId);
                var lenCount = numLenSupport.Select(it => new LotteryVote.Entity.CompanyNumLen.NumLenItem { Length = it.Length.Length, Count = it.Count });
                numLens.Add(new CompanyNumLen
                {
                    CompanyId = company.CompanyId,
                    NumLenList = lenCount.ToList()
                });
            }
            var baseStr = Convert.ToBase64String(Encoding.UTF8.GetBytes(JSONHelper.ToJson(numLens)));
            CookieSerializer cs = new CookieSerializer("CompanyNumLen", baseStr);
            cs.SaveCookie();
        }
    }
}
